package org.geeks.repository;

import org.geeks.domain.User;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

/**
 * User Repository
 * 
 * @author Geek4J
 *
 */
public interface UserRepository extends CrudRepository<User, Long> {

	/**
	 * export endpoint via repository
	 * 
	 * @param username
	 *            用户名
	 * @return Page<User> 用户分页信息
	 */
	@Cacheable("10S")
	@Query("select u from User u where u.username like %?1%")
	Page<User> findByUsernameLike(@Param("username") String username, Pageable page);

	/**
	 * export endpoint via repository
	 * 
	 * @param age
	 *            年龄
	 * @return Page<User> 用户分页信息
	 */
	Page<User> findByAge(@Param("age") Integer age, Pageable page);
}
